package l.l.w.leetcode._050Pow;

/**
 * Created by llw on 2017/11/16.
 */
public class _050Pow {

    public double myPow(double x, int n) {
        if(n == 1) return x;
        if(n == 0) return 1;
        if((n & 1) == 1){
            // 右移进行除2操作，限于正数。
            if(n > 0) return x*myPow(x*x,n/2);
            else return  1/x * myPow(x * x,n/2);
        }else{
            return myPow(x * x,n/2);
        }
    }

    public static void main(String[] args) {
        double x = 34.00515;
        int n = -3;
        double result = new _050Pow().myPow(x, n);
        System.out.println(result);
    }
}
